
import React, { Component } from 'react';
import {
	View,
	Text,
	TextInput,
	TouchableOpacity
} from 'react-native';

import Welcome from './Welcome';

//用户登录
class Login extends React.Component {

	//初始化
	constructor(props) {
		super(props);
		this.state = {//初始化状态
			name: null,
			age: null,
			userToken:"23690999",
		}
	}

	//打开的新页面
	openPage() {
		//导航方法
		this.props.navigator.push({
			component: Welcome,
			params: {//页面之间传递参数
				name: this.state.name,
				age: this.state.age,
				userToken:this.state.userToken,//用户token,
				changeMyAge: (age) => {
					this.setState({ age })
				}
			}
		})
	}

	render() {
		return (
			<View style={{ flex: 1, alignItems: 'center', backgroundColor: '#FFFFFF' }}>
				<Text>登录页</Text>
				<TextInput
					value={this.state.name}
					onChangeText={name => this.setState({ name })}
					placeholder={'任意输入。。。'}
					style={{ height: 40, width: 300,padding:10,backgroundColor:'red',margin:30}} />
				<Text>输入改变: {this.state.age ? this.state.age : 'Unknown'}</Text>

				<Text>输入的是:{this.state.name}</Text>
				<TouchableOpacity onPress={this.openPage.bind(this)} >
					<Text style={{ color: '#55ACEE'}}>数据传递</Text>
				</TouchableOpacity>
			</View>
		);
	}
}

export default Login;